package com.bbx.mapper_reduce_demo.writable;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class PhoneReduce extends Reducer<Text,PhoneInfoWritable,Text ,PhoneInfoWritable> {
    PhoneInfoWritable phoneInfoWritable = new PhoneInfoWritable();
    @Override
    protected void reduce(Text key, Iterable<PhoneInfoWritable> values, Context context) throws IOException, InterruptedException {
        Long upFlow = 0L;
        Long downFlow = 0L;
        for (PhoneInfoWritable value:values){
            upFlow += value.getUpFlow();
            downFlow += value.getDownFlow();
        }
        phoneInfoWritable.setValue(upFlow,downFlow);
        context.write(key,phoneInfoWritable);
    }
}
